﻿using System.IO;
using GraphProcessor;
using UnityEditor;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    public class LevelServiceGraph : BaseGraph
    {
        [MenuItem("Assets/Create/GraphProcessor/LevelServiceGraph", false, 10)]
        public static void CreateLevelServiceGraphProcessor()
        {
            var graph = ScriptableObject.CreateInstance<LevelServiceGraph>();
            ProjectWindowUtil.CreateAsset(graph, "LevelServiceGraphProcessor.asset");
        }
        
        [MenuItem("ToolApp/关卡编辑器/服务Graph替换为LevelServiceGraph", false, 95)]
        public static void BaseGraph2LevelServiceGraph()
        {
            var rDirPath = "Assets/EditorConfig/LevelConfig/LevelService";
            var rDirs = Directory.GetDirectories(rDirPath);
            foreach (var rDir in rDirs)
            {
                var rFiles = Directory.GetFiles(rDir);
                foreach (var rFile in rFiles)
                {
                    if (!rFile.EndsWith("asset"))
                    {
                        continue;
                    }
                    var rTxt = File.ReadAllText(rFile);
                    // 替换basegraph为LevelServiceGraph
                    rTxt = rTxt.Replace("m_Script: {fileID: 11500000, guid: 31390c44c9f3a3d40b424bf6821999a2, type: 3}",
                        "m_Script: {fileID: 11500000, guid: 2ebc41d0844e5d149af9f88827122926, type: 3}");
                    File.WriteAllText(rFile, rTxt);
                }
            }
            AssetDatabase.Refresh();
        }
    }
}